home *** CD-ROM | disk | FTP | other *** search
- Path: news.nas.com!news
- From: gldnspud@kali.nas.com (Matt Scott)
- Newsgroups: comp.lang.c++
- Subject: Functions in functions using function objects
- Date: Thu, 04 Apr 1996 23:59:46 GMT
- Organization: Everyone's Software
- Message-ID: <4k1nus$8h1@barad-dur.nas.com>
- NNTP-Posting-Host: kali.nas.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- I was experimenting with various C++ constructs lately, and I thought
- of an idea that might help me implement a Pascal construct that I
- really enjoy but that isn't present in C or C++.
-
- I always liked the fact that Pascal was a block-structured language,
- and that you could have functions (and procedures, for all you Pascal
- types out there) inside other functions, which would be local to only
- those functions that they were defined in.
-
- Since C and C++ are not block-structured, this is impossible. I did
- find a way around it, though:
-
- #include <iostream.h>
-
- void foo(void)
- {
- struct foo__bar
- {
- void operator()(void)
- {
- cout << "foobar!\n";
- }
- } bar;
-
- bar();
- bar();
- }
-
- int main(void)
- {
- foo();
- return 0;
- }
-
-
- However, foo__bar::operator() is generated as an inline function. I
- would like to coax the language into giving me a non-inline function
- (possibly to implement recursion) using something similar to the
- above. This obviously cannot be implemented as:
-
- void foo(void)
- {
- struct foo__bar
- {
- void operator()(void);
- } bar;
-
- void foo__bar::operator()(void)
- {
- cout << "foobar!\n";
- }
-
- bar();
- bar();
- }
-
- Does anyone have any ideas on this subject?
-
- -Matt
-
-
-